package com.jokelandave.sportzbetz.client.presenters;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.Widget;
import com.jokelandave.sportzbetz.client.events.GoogleLoginEvent;


public class WelcomePresenter implements Presenter {

	public interface IWelcomeView
	{
		HasClickHandlers getLoginButton();
		Widget asWidget();
	}
	
	IWelcomeView view;
	EventBus eventBus;

	
	public WelcomePresenter(EventBus eventBus, IWelcomeView view)
	{
		this.view = view;
		this.eventBus = eventBus;
	}
	
	private void bind()
	{
		view.getLoginButton().addClickHandler(new ClickHandler(){

			@Override
			public void onClick(ClickEvent event) 
			{
				eventBus.fireEvent(new GoogleLoginEvent());
			}
			
		});
	}
	
	@Override
	public void go(HasWidgets container) 
	{
		bind();
		container.clear();
		container.add(view.asWidget());
	}

}
